package com.foxmail.yusp.mycloud;

import android.app.DialogFragment;
import android.content.Context;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText;
import android.widget.TextView;

import java.util.List;


public class ScheduleAdapter extends RecyclerView.Adapter<ScheduleAdapter.ViewHolder> {

    private List<Schedule> schedules;
    private Context context;

    public ScheduleAdapter(Context context, List<Schedule> schedules) {
        this.context = context;
        this.schedules = schedules;
    }

    private Context getContext() {
        return context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        Context context = parent.getContext();
        LayoutInflater inflater = LayoutInflater.from(context);
        View view = inflater.inflate(R.layout.layout_schedule, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Schedule schedule = schedules.get(position);

        holder.idx.setText(schedule.getIdx());
        holder.start.setText(schedule.getStart());
        holder.on_time.setText(schedule.getOn_time());
    }

    @Override
    public int getItemCount() {
        return schedules.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {
        private TextView idx;
        private EditText start;
        private EditText on_time;

        public ViewHolder(View view) {
            super(view);
            idx = view.findViewById(R.id.idx);
            start = view.findViewById(R.id.start);
            on_time = view.findViewById(R.id.on_time);

/*            start.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {

                }
            });*/
        }
    }

    // 时间选择
/*    public void clockTimeClick(View view) {
        DialogFragment newFragment = new TimePickerFragment();
        Bundle bundle = new Bundle();
        bundle.putInt("id", view.getId());
        newFragment.setArguments(bundle);
        newFragment.show(context.getFragmentManager(), "timePicker");
    }*/
    //
}
